import request from '@/utils/request'

// api 后端接口
// 请求数据墙
export function initDataWall(data) {
  return request({
    url: '/vue-admin-template/user/initDataWall',
    method: 'post',
    data: data
  })
}

// method
// 选择器option
export function initOptions(data) {
  var options = []
  for (var i = 0; i < data.length; i++) {
    const element = data[i]
    options.push({ value: element.deviceID, label: element.deviceID, describe: element.address })
    console.log(element.deviceID)
  }
  return options
}

// 请求数据接口
export function requestData(data) {
  return request({
    url: '/vue-admin-template/user/datawall',
    method: 'post',
    data: data
  })
}

// 处理数据返回
export function getChartDatas(datas, key) {
  var xAxisLabel = [] // 记录x轴label
  var seriesData = [] // 记录系列数据
  for (var i = 0; i < datas.length; i++) {
    xAxisLabel.push(datas[i].date_ts.toString())
    seriesData.push(datas[i][key].toFixed(2))
  }
  return { xAxisLabel: xAxisLabel, seriesData: seriesData }
}
